// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import iView from 'iview'
import 'iview/dist/styles/iview.css'
import App from './App'
import router from './router'
import Vuex from 'vuex'

// import Element from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
import VueI18n from 'vue-i18n'
import zhLocale from 'iview/src/locale/lang/zh-CN'
import enLocale from 'iview/src/locale/lang/en-US'
import Locales from './locale'

//引入自定义基础css
import './assets/style/_settings.less'

import './libs/interceptors.js'
// import '../static/g2-2.3.13.js'
// import '../static/g2-plugin-slider-1.2.1.js'
import $ from 'jquery'

Vue.config.productionTip = false

// Vue.use(Element)
Vue.use(VueI18n)
Vue.use(iView)
Vue.use(Vuex)

// 自动设置语言
const navLang = navigator.language
const localLang = navLang === 'zh-CN' || navLang === 'en-US' ? navLang : false
const lang = window.localStorage.lang || localLang || 'zh-CN'
Vue.config.lang = lang
// 多语言配置
const locales = Locales
const mergeZH = Object.assign(zhLocale, locales['zh-CN'])
const mergeEN = Object.assign(enLocale, locales['en-US'])

Vue.locale('zh-CN', mergeZH)
Vue.locale('en-US', mergeEN)

// 状态管理
const store = new Vuex.Store({
  state: {
    lang: ''
  },
  mutations: {
    switchLang(state, lang) {
      state.lang = lang
      Vue.config.lang = lang
    }
  }
})

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title + ' - 学创校园'
  } else {
    document.title = '学创校园'
  }
  next()
})
new Vue({
  el: '#app',
  router,
  store: store,
  template: '<App/>',
  components: { App }
})
